<template>

  <div>
    <el-dropdown trigger="click" class="international" @command="handleSetLanguage">
      <div class="size-icon--style">
        <svg-icon class-name="international-icon" icon-class="language" />
        <!--      <span class="language">{{ locale === 'en' ? '英文' : '中文' }}</span>-->
      </div>
      <template #dropdown>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item  :disabled="appStore.language === 'en'" command="en">English</el-dropdown-item>
          <el-dropdown-item  :disabled="appStore.language === 'zh'" command="zh">中文</el-dropdown-item>
          <el-dropdown-item  :disabled="appStore.language === 'ja'" command="ja">日本語</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>



</template>

<script setup>
import { changeLanguage } from "@/api/login";
import useAppStore from '@/store/modules/app'
import { getToken } from '@/utils/auth'
const { proxy } = getCurrentInstance();

const appStore = useAppStore()


function handleSetLanguage(value) {
  console.log("value:" + value)
  // this.$i18n.locale = value
  // this.$store.dispatch('app/setLanguage', value)
  useAppStore().setLanguage(value)
  if (!getToken()) {
    window.location.reload();
    return
  }
  proxy.$modal.msgSuccess("设置语言成功");
  changeLanguage(value).then(response => {
    window.location.reload();
  });
}

// export default {
//   computed: {
//     language() {
//       return appStore.language
//       // this.$store.getters.language
//     }
//   },
//   mounted() {
//     console.log("language:" + this.language)
//     if (!this.language){
//       let language = navigator.language.split('-')[0] // 获取当前计算机语言，默认为 'zh' 或 'en'
//       if (language !== 'zh' && language !== 'en' && language !== 'ja') {
//         language = 'en'; // 如果不是中文或英文，默认设置为中文
//       }
//       useAppStore().setLanguage(language)
//       console.log("language2:" + this.language)
//     }
//   },
//   methods: {
//     handleSetLanguage(value) {
//       console.log("value:" + value)
      // this.$i18n.locale = value
      // this.$store.dispatch('app/setLanguage', value)
      // useAppStore().setLanguage(value)
      // if (!getToken()) {
      //   window.location.reload();
      //   return
      // }
      // this.$message({ message: '设置语言成功', type: 'success' })
      // changeLanguage(value).then(response => {
      //   window.location.reload();
      // });
  //   }
  // }
// }
</script>

<style lang='scss' scoped>
.size-icon--style {
  font-size: 18px;
  line-height: 50px;
  padding-right: 7px;
}
</style>